package Pixiv;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;

public class Search {
	public  List<String> getURL(CloseableHttpResponse closeableHttpResponse,int i) throws UnsupportedOperationException, IOException {
		List<String>URL=new ArrayList<>();
		
		HttpEntity SearchEntity=closeableHttpResponse.getEntity();
        
        if (SearchEntity!=null) {
			java.io.InputStream inputStream;
			inputStream=SearchEntity.getContent();
			BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"utf-8"));
			String line="";
			if (i==1) {
				while ((line=bufferedReader.readLine())!=null) {
					String findurl="https:\\/\\/i\\.pximg\\.net\\/c\\/240x480.*?\\.jpg";
					Pattern findPattern=Pattern.compile(findurl);
					Matcher findMatcher=findPattern.matcher(line);
					while (findMatcher.find()) {
						String url=findMatcher.group(0);
						url=url.replace("c/240x480", "img-original");
						url=url.replace("_master1200", "");
						url=url.replace("img-master/", "");
						URL.add(url);
					}
				}
			} else {
				while ((line=bufferedReader.readLine())!=null) {
					String findURL="https:\\/\\/i\\.pximg\\.net.*?\\.jpg";
					Pattern findpattern=Pattern.compile(findURL);
					Matcher findmatcher=findpattern.matcher(line);
					while (findmatcher.find()) {
						String xxx0=findmatcher.group(0);
					    String xxx1=xxx0.replace("c/150x150", "img-original");
						String xxx2=xxx1.replace("_master1200", "");
						xxx2=xxx2.replace("img-master/", "");
						URL.add(xxx2);
					}
				}	
			}
	}
	return URL;
	}
}
